//
//  FindViewController.m
//  carSecretary
//
//  Created by huangliru on 14-9-4.
//  Copyright (c) 2014年 huangliru. All rights reserved.
//

#import "FindViewController.h"
#import "ForgetViewController.h"
#import "LoginViewController.h"
#import "ChangeViewController.h"
@interface FindViewController ()

@end

@implementation FindViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIControl *control = [[UIControl alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    
    //创建一个导航栏
    UINavigationBar *bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 18, 320, 44)];
    //创建一个导航栏集合
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];
    //创建一个左边按钮
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(backButton)];
    //设置导航栏内容
    [navigationItem setTitle:@"邮箱找回密码"];
    //把导航栏集合添加入导航栏中，设置动画关闭
    [bar pushNavigationItem:navigationItem animated:NO];
    //把左按钮添加入导航栏集合中
    [navigationItem setLeftBarButtonItem:leftButton];
    bar.backgroundColor = [UIColor grayColor];
    [control addSubview:bar];
    
    UIButton *phone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    phone.frame = CGRectMake(0, 60, 160, 45);
    phone.tintColor = [UIColor blackColor];
    [phone setTitle:@"电话找回" forState:UIControlStateNormal];
    [phone addTarget:self action:@selector(phonePress) forControlEvents:UIControlEventTouchUpInside];
    [control addSubview:phone];
    
    UIButton *email = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    email.frame = CGRectMake(160, 60, 160, 45);
    email.tintColor = [UIColor blackColor];
    [email setTitle:@"邮箱找回" forState:UIControlStateNormal];
    [control addSubview:email];
    
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(27, 148, 103, 30)];
    lable.textColor = [UIColor blackColor];
    lable.text = @"用户名：";
    [control addSubview:lable];
    
    // 初始化账号输入
    self.userNameText = [[UITextField alloc]initWithFrame:CGRectMake(48 , 195, 224, 30)];
    //让字体大小自适应控件的区域
    [self.userNameText setBorderStyle:UITextBorderStyleLine];
    [self.userNameText  setAdjustsFontSizeToFitWidth:YES];
    self.userNameText.placeholder = @"请输入您的用户名";
    //设置委托对象
    self.userNameText.delegate = self;
    //添加到本视图
    [control addSubview: self.userNameText];
    
    // 初始化账号输入
    self.testText = [[UITextField alloc]initWithFrame:CGRectMake(48 , 324, 224, 30)];
    self.testText.tag = 12;
    //让字体大小自适应控件的区域
    [self.testText setBorderStyle:UITextBorderStyleLine];
    [self.testText  setAdjustsFontSizeToFitWidth:YES];
    self.testText.placeholder = @"请输入您收到的邮箱验证码";
    //设置委托对象
    self.testText.delegate = self;
    //添加到本视图
    [control addSubview: self.testText];
    
    // 获取验证码按钮
    self.getTest = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.getTest.frame = CGRectMake(87, 263, 146, 40);
    self.getTest.tintColor = [UIColor blackColor];
    [self.getTest setTitle:@"获取验证码" forState:UIControlStateNormal];
    [self.getTest setBackgroundImage:[UIImage imageNamed:@"213.png"] forState:UIControlStateNormal];
    [self.getTest addTarget:self action:@selector(getTestButtonPress) forControlEvents:UIControlEventTouchUpInside];
    [control addSubview:self.getTest];
    
    //提交按钮
    self.submitButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.submitButton.frame = CGRectMake(105, 431, 111, 48);
    self.submitButton.tintColor = [UIColor blackColor];
    [self.submitButton setTitle:@"提交" forState:UIControlStateNormal];
    [self.submitButton setBackgroundImage:[UIImage imageNamed:@"213.png"] forState:UIControlStateNormal];
    [self.submitButton addTarget:self action:@selector(submitButtonPress) forControlEvents:UIControlEventTouchUpInside];
    [control addSubview:self.submitButton];
    
    
    
    
    [control addTarget:self action:@selector(textFieldShouldReturn:) forControlEvents:UIControlEventTouchDown];
    self.view = control;
}
//实现textfielddelegate方法
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    [UIView  beginAnimations:@"aa" context:nil];
    [UIView setAnimationDuration:0.3];
    if ([textField tag] == 12)
    {
        CGRect frame = self.view.frame;
        frame.origin.y -= 30;
        self.view.frame = frame;
    }
    [UIView commitAnimations];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [UIView beginAnimations:@"aa" context:nil];
    self.view.frame = CGRectMake(0, 0, 320, 560);
    [UIView setAnimationDuration:0.3];
    [UIView commitAnimations];
    
    
    [self.userNameText resignFirstResponder];
    [self.testText resignFirstResponder];
    return YES;
}
// 跳转
-(void)phonePress
{
    ForgetViewController *phoneVC = [[ForgetViewController alloc]init];
    [self presentViewController:phoneVC animated:NO completion:nil];
}

// 导航栏返回按钮
-(void)backButton
{
    LoginViewController *loginVC = [[LoginViewController alloc]init];
    [self presentViewController:loginVC animated:NO completion:nil];
}
// 获取验证码
-(void)getTestButtonPress
{
    
}
// 提交
-(void)submitButtonPress
{
    ChangeViewController *changeVC = [[ChangeViewController alloc]init];
    [self presentViewController:changeVC animated:NO completion:nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
